package com.ai.platform.common.page;

import java.sql.Connection;
import java.sql.SQLException;

public abstract class Dialect {

    public static Dialect createDialect(Connection connection) throws SQLException {
        //通过driverName是否包含关键字判断
        if (connection.getMetaData().getDriverName().toUpperCase().contains("MYSQL")) {
            return new MysqlDialect();
        } else if (connection.getMetaData().getDriverName().toUpperCase().contains("Oracle")) {
            return new OracleDialect();
        }
        return new Dialect() {
            @Override
            String getLimitString(String sql, int offset, int limit) {
                return null;
            }
        };
    }

    abstract String getLimitString(String sql, int offset, int limit);
}
